package com.example.jooqdemo.dao;

import com.generated.jooq.Tables;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import static com.generated.jooq.tables.User.USER;


/**
 * @Description: java类作用描述
 * @Author: czw
 * @date: 2018/4/28
 */
@Repository
public class UserDao {

    @Autowired
    protected DSLContext dsl;

    public int saveUser(){
        int execute = dsl.insertInto(Tables.USER, Tables.USER.NAME, Tables.USER.PASSWORD)
                .values("Hermann", "Hesse")
                .execute();
        return execute;
    }

    public void getUser(){
        Result<Record> fetch = dsl.select().from(USER).orderBy(USER.ID).limit(1, 20).fetch();
        System.out.println(fetch);
    }

    public int getNub() {
        int nub = dsl.fetchCount(Tables.USER);
        System.out.println("DSLContext ======> "+nub);
        return nub;
    }

    public void insertUser(){
                int execute = dsl.insertInto(Tables.USER, Tables.USER.NAME, Tables.USER.PASSWORD)
                .values("Hermann", "Hesse")
                .execute();
        System.out.println("execute ======> "+execute);

        int execute1 = dsl.insertInto(Tables.TODOS
                ,Tables.TODOS.ID
                , Tables.TODOS.DESCRIPTION
                , Tables.TODOS.TITLE).values(
                15L
                ,"王五"
                , "王五").execute();

        System.out.println("execute1 ======> "+execute1);
        int i = 1 / 0;
    }
}
